package com.kaesar.leetcode.LeetCode_301_350;

public class LeetCode_338 {
    /**
     * 使用库函数 Integer.bitCount 直接获取整数对应的二进制的1的个数
     *
     * @param n
     * @return
     */
    public static int[] countBits(int n) {
        int[] result = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            result[i] = Integer.bitCount(i);
        }
        return result;
    }

    public static void main(String[] args) {
        for (int i : countBits(100)) {
            System.out.println(i);
        }
    }
}
